package org.example.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.print.Doc;

/**
 * Swagger文档配置：可以根据后端配置的信息自动生成api文档
 * @author wusen
 * @date 2021/1/11
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class Swagger2 {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build()
                ;

    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("破破烂烂的项目")
                .description("这里些什么~~")//简介
                .termsOfServiceUrl("com.liu.testing.testing")
                .contact("程序猿")//作者
                .version("version 1.0")//版本
                .build();
    }
}
